<template>
  <div class="main" v-if="normalList.length > 0">
    <div v-for="(item, index) in normalList" :key="item.id">
      <div class="preliminary-title">
        <img src="@/assets/cutomer/preliminary.png" alt="" />
        <div class="title-text" v-if="activeIndex == '1' || activeIndex == '2' || activeIndex == '3'">
          <span v-if="activeIndex == '1' || activeIndex == '2'">发送消息：{{item.taskName}}</span>
          <span v-if="activeIndex == '3'">群发消息：{{item.taskName}}</span>
          <span class="title-time">{{item.sendTime}}</span>
        </div>
        <div class="title-text" v-if="activeIndex == '4'">
          <span>企业朋友圈</span>
          <span class="title-time">{{item.sendTime}}</span>
        </div>
        <div class="title-text" v-if="activeIndex == '5'">
          <div>客户旅程：{{item.taskName}}</div>
          <span class="title-time">{{item.sendTime}}</span>
        </div>
      </div>
      <div v-if="activeIndex == '5'" style="margin: 10px 0 20px 50px">触达形式：{{ teachTypeOpt[item.reachType] }}</div>
      <div class="preliminary-main">
        <div :class="index == normalList.length - 1 ? 'finish-line' : 'line'"></div>
        <div class="info-right">
          <!-- 文本类 -->
          <template v-if="item.content">
            <div class="text-style">{{ item.content }}</div>
          </template>
          <div class="info" v-for="(val, idx) in item.weMaterialList" :key="idx + 'n'">
            <!-- 图片类 -->
            <template v-if="handleSuffixType(val.materialUrl) === 'image'">
              <div class="dto">
                <img class="square" :src="val.materialUrl">
                <div class="text">
                  <div class="des">{{ val.materialName }}</div>
                </div>
              </div>
            </template>
            <!-- 视频类 -->
            <template v-if="handleSuffixType(val.materialUrl) === 'mp4'">
              <div class="dto">
                <div class="square">
                  <video style="width: 100%; height: 100%" ref="vueMiniPlayer">
                    <source :src="val.materialUrl" type="video/mp4" />
                  </video>
                </div>
                <div class="text">
                  <div class="des">{{ val.name }}</div>
                </div>
              </div>
            </template>
            <!-- 音乐类 -->
            <template v-if="handleSuffixType(val.materialUrl) === 'mp3'">
              <div class="dto">
                <div class="square">
                  <audio :src="val.materialUrl"></audio>
                </div>
                <div class="text">
                  <div class="des">{{ val.name }}</div>
                </div>
              </div>
            </template>
            <!-- 文档类 -->
            <template
              v-if="handleSuffixType(val.materialUrl) === 'xlsx' || handleSuffixType(val.materialUrl) === 'word' || handleSuffixType(val.materialUrl) === 'txt' || handleSuffixType(val.materialUrl) === 'pdf'">
              <div class="dto">
                <div class="square">
                  <img :src="val.materialUrl">
                </div>
                <div class="text">
                  <div class="des">{{ val.name }}</div>
                </div>
              </div>
            </template>
            <!-- 二维码 -->
            <template v-if="val.mediaType == '1'">
              <div class="dto">
                <div class="square">
                  <img :src="val.materialUrl">
                </div>
                <div class="text">
                  <div class="des">{{ val.name }}</div>
                </div>
              </div>
            </template>
          </div>
          <p>分享人：{{item.sharePerson}}</p>
        </div>
      </div>
    </div>
  </div>
  <div v-else>
    <el-empty description="暂无数据"></el-empty>
  </div>
</template>

<script>
import { suffixType } from "@/utils/suffixType"

export default {
  props: {
    activeIndex: {
      type: String,
      default: '1'
    },
    normalList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      teachTypeOpt: ['', '消息', '朋友圈'],
      mediaTypeToText: {
        '11': "h5链接",
        '5': "海报",
        '3': "文件",
        '4': "文章",
        '99': "险种",
        '7': "多媒体",
        '8': "本地上传",
        '9': "",
        '10': "问卷",
        '100': "本地上传文件",
      },
    }
  },
  methods: {
    handleSuffixType(filename) {
      if (!filename) return
      const simpleFileName = filename.split("?sign=")[0]
      return suffixType(simpleFileName);
    },
  }
};
</script>

<style lang="scss" scoped>
.main {
  padding: 0 20px;
  .preliminary-title {
    display: flex;
    align-items: center;
    .title-text {
      margin-left: 15px;
      width: 100%;
      display: flex;
      justify-content: space-between;
      font-size: 16px;
      font-weight: 500;
      color: #2a2a2a;
      .title-time {
        font-size: 14px;
        font-weight: 400;
        color: #cccccc;
        line-height: 16px;
      }
    }
  }
  .preliminary-main {
    display: flex;
    margin-top: 11px;
    margin-bottom: 15px;
    .info-right {
      width: 100%;
      margin-left: 20px;
      .text-style{
        margin-bottom: 20px;
      }
    }

    .info {
      background: #f6f6f6;
      border-radius: 2px;
      font-size: 14px;
      color: #999999;
      line-height: 20px;
      padding: 8px 0 10px 17px;
      margin-bottom: 20px;
      .h5-style{
        margin: 10px 0;
      }
      .dto {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        margin: 10px 0;
        .square {
          display: inline-block;
          width: 45px;
          height: 45px;
          border-radius: 4px;
          overflow: hidden;
          img{
            width: 45px;
          }
        }
        .text {
          width: 160px;
          .des {
            width: 100%;
            padding: 0 10px;
            margin: 2px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .size {
            margin: 10px 0 0 2px;
            padding: 0 10px;
            color: #999;
            font-size: 12px;
          }
        }
      }
    }
  }
  .line {
    width: 0;
    border-right: 1px dashed #cccccc;
    margin: 0 16px;
  }
  .finish-line {
    margin: 0 16px;
  }
}
</style>
